package com.oa.admin.service.impl;

import com.joneying.common.annotation.CommonService;
import com.oa.admin.dto.DocumentAddDTO;
import com.oa.admin.entity.Document;
import com.oa.core.PageResult;
import com.oa.admin.entity.DocumentPermission;
import com.oa.admin.mapper.DocumentPermissionMapper;
import com.oa.admin.service.IDocumentPermissionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;

/**
 * <p>
 * 文档权限表 服务实现类
 * </p>
 *
 * @author syb123
 * @since 2019-01-22
 */
@Service
public class DocumentPermissionServiceImpl extends ServiceImpl<DocumentPermissionMapper, DocumentPermission> implements IDocumentPermissionService {

    private final DocumentPermissionMapper documentPermissionMapper;

    @Autowired
    public DocumentPermissionServiceImpl(DocumentPermissionMapper documentPermissionMapper) {
        this.documentPermissionMapper = documentPermissionMapper;
    }

    @Override
    @CommonService
    public PageResult<DocumentPermission> findList(Integer pageNum, Integer pageSize) {
        if(pageNum == null){
            List<DocumentPermission> list = documentPermissionMapper.findList();
            return new PageResult<>(list);
        }else{
            // 当前页，总条数 构造 page 对象
            Page<DocumentPermission> page = new Page<>(pageNum, pageSize);
            //查询
            List<DocumentPermission> list = documentPermissionMapper.findList(page);
            return new PageResult<>(list);
        }
    }

    /**
    * 根据id查询
    */
    @Override
    @CommonService
    public DocumentPermission findDocumentPermissionById(String id){
        return documentPermissionMapper.findById(id);
    }
}
